import time

from appium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as es
from time import sleep

class test__01():

    def __init__(self):
        cap={
            "platformName": "Android",
            "appium:deviceName": "emulator-5554",
            "appPackage": "com.kongfz.app",
            "appActivity": "com.kongfz.app.home.mvvm.homepage.HomeActivity",
            "noReset":True
        }
        #加载驱动
        self.dr=webdriver.Remote("http://127.0.0.1:4723/wd/hub",cap)

        #设置隐式等待时间
        self.dr.implicitly_wait(60)

        #设置强制等待时间
        sleep(40)
    #方法一
    def loc1(self,loc):
        try:
            return self.dr.find_element(*loc)
        except Exception as f:
            print("未找到元素",loc)

    #方法二
    def loc2(self, loc):
        try:
            return self.dr.find_element_by_android_uiautomator(loc)
        except Exception as f:
            print("未找到元素", loc)
    #方法三
    def loc3(self, loc):
        try:
            return WebDriverWait(self.dr,10).until(es.presence_of_element_located(loc))
        except Exception as f:
            print("未找到元素", loc)
    #方法四
    def loc4(self, loc,key):
        if type(loc)==str:
            ele=self.loc2(loc)
        else:
            ele=self.loc1(loc)
            return ele.get_attribute(key)
    #方法五
    def loc5(self, filep):
        t=time.strftime("%Y%m%d%H%M%S",time.localtime())

        self.dr.save_screenshot(t+filep)

    #方法六
    def loc6(self, loc):
        self.dr.quit()

